package com.etc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.etc.entity.Employee;
import com.etc.service.EmployeeService;
import com.etc.util.ResponseData;
import com.github.pagehelper.Page;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 
 * @ClassName: EmployeeController
 * @Description: @RestController = @Controller + @ResponseBody
 * @author knowno
 * @date 2022年4月7日 上午9:51:24
 *
 */
@RestController
@Api(value = "员工管理控制器", description = "员工管理接口")
public class EmployeeController {

	// 注入一个service
	@Autowired
	private EmployeeService service;

	/**
	 * 
	 * @param page     页码
	 * @param limit    每页记录数
	 * @param keywords 查询关键字
	 * @return
	 */
	@GetMapping(value = "emp")
	@ApiOperation(value = "员工的模糊查询", httpMethod = "GET", notes = "员工模糊查询方法", response = ResponseData.class)
	public ResponseData<Employee> getEmp(
			@RequestParam(value = "page", required = true, defaultValue = "1") Integer page,
			@RequestParam(value = "limit", required = true, defaultValue = "10") Integer limit,
			@RequestParam(value = "keywords", required = true, defaultValue = "") @ApiParam(value = "关键字", name = "keywords", required = false) String keywords) {
		Page<Employee> pages = service.getByPage(page, limit, keywords);

		ResponseData<Employee> rdata = new ResponseData<Employee>(pages.getTotal(), pages.getResult());

		return rdata;
	}

}
